<template>
	<div class="sys-pos-container">
		<el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" width="700px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit />
					</el-icon>
					<span> {{ props.title }} </span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" class="fl"  label-width="auto">
				<el-form-item label="仓库名称" prop="whName"
					:rules="[{ required: true, message: '仓库名称不能为空', trigger: 'blur' }]">
					<el-input v-model="state.ruleForm.whName" placeholder="仓库名称" clearable />
				</el-form-item>
				<el-form-item label="仓库地址">
					<el-input v-model="state.ruleForm.whAddress" placeholder="仓库地址" clearable />
				</el-form-item>
				<el-form-item label="仓库类型"
					>

					<el-select v-model="state.ruleForm.whType" placeholder="请选择容器类型" style="width: 240px">
						<el-option v-for="item in state.wTypes" :key="item.value" :label="item.name"
							:value="item.value" />
					</el-select>
					<!-- <el-radio-group v-model="state.ruleForm.whType" class="ml-4">
						<el-radio :label="1">线边仓</el-radio>
						<el-radio :label="0">工厂仓</el-radio>
					</el-radio-group> -->
				</el-form-item>
				<el-form-item label="状态">
					<el-switch v-model="state.ruleForm.whStatus" inline-prompt active-text="启用" inactive-text="禁用"
						:active-value="0" :inactive-value="1" />
				</el-form-item>
				<el-form-item label="备注" prop="whRemake">
					<el-input v-model="state.ruleForm.whRemake" placeholder="请输入备注内容" clearable type="textarea"
						class="extra" />
				</el-form-item>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel">取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup name="sysEditPos">
import { reactive, ref } from 'vue';
import { getAPI } from '/@/utils/axios-utils';
import { SysDictDataApi, SysPosApi } from '/@/api-services/api';
import { WmsApi } from '/@/api/wh';
import { ElMessage } from 'element-plus';

const props = defineProps({
	title: String,
});
const emits = defineEmits(['handleQuery']);
const ruleFormRef = ref();
const state = reactive({
	isShowDialog: false,
	ruleForm: {

	},
	wTypes: []
});

// 打开弹窗
const openDialog = async (row: any) => {
	var res = await getAPI(SysDictDataApi).apiSysDictDataDataListCodeGet('w_type');
	state.wTypes = res.data.result;
	state.ruleForm = JSON.parse(JSON.stringify(row));
	console.log(state.ruleForm.whStatus);

	state.isShowDialog = true;
	ruleFormRef.value?.resetFields();
};

// 关闭弹窗
const closeDialog = () => {
	emits('handleQuery');
	state.isShowDialog = false;

	
};

// 取消
const cancel = () => {
	state.isShowDialog = false;
};

// 提交
const submit = () => {
	ruleFormRef.value.validate(async (valid: boolean) => {
		if (!valid) return;
		console.log(state.ruleForm.id);

		if (state.ruleForm.id) {
			console.log(state.ruleForm);

			await WmsApi().WhPagePut(state.ruleForm)
				.then(function (res) {
					ElMessage.success('修改成功');
			
					
					closeDialog();
				})
				.catch(function (error) {
					console.log(error);
				});
		} else {

			await WmsApi().WhPageAdd(state.ruleForm)
				.then(function (res) {
					ElMessage.success('新增成功');
					
					closeDialog();
				})
				.catch(function (error) {
					console.log(error);
				});

		}
	});
}

// 导出对象
defineExpose({ openDialog });
</script>
<style lang="scss" scoped>
.fl {
	width: 70%;
	margin: 20px auto;
	
}
</style>